package com.simple.core.endpoint;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 接口失效，将标记@ApiIgnore的接口不可访问
 *
 * @author FanXing
 * @date 2023年03月05日 0:09
 */
@Slf4j
@Aspect
@Component
public class DisableApiAspect {

    @Autowired
    private HttpServletResponse httpServletResponse;

    @Around("@annotation(springfox.documentation.annotations.ApiIgnore)")
    public void disable(JoinPoint joinPoint) throws IOException {
        httpServletResponse.sendError(HttpStatus.NOT_FOUND.value(), "Not found");
    }
}
